<?php

namespace App\Service\CallingCards;


use App\Models\Common\ConfigModel;

class RegionalCodeService
{
    public static function getCodeByAddress($province, $city): array
    {
        $list = ConfigModel::getValueNewJson('callingCards', 'xiaokeAreas', 600);
        if (!is_array($list) || empty($list)) {
            return [];
        }
        $info = [];
        /**
         * {
         * "province_code": "110000",
         * "province": "北京市",
         * "city_code": "110100",
         * "city": "北京市",
         * },
         */
        foreach ($list as $v) {
            if ($v['name'] == trim($province)) {
                foreach ($v['childs'] as $vv) {
                    if ($vv['name'] == trim($city)) {
                        $info = [
                            'province_code' => $v['code'],
                            'province'      => $v['name'],
                            'city_code'     => $vv['code'],
                            'city'          => $vv['name'],
                        ];
                    }
                }
            }
        }
        return $info;
    }
}
